package com.lifeng.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.lifeng.entity.ContentCategory;
import com.lifeng.mapper.ContentCategoryMapper;
import com.lifeng.service.IContentCategoryService;
import com.lifeng.util.PageResult;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lifeng
 * @since 2025-01-14
 */
@Service
public class ContentCategoryServiceImpl extends ServiceImpl<ContentCategoryMapper, ContentCategory> implements IContentCategoryService {
    @Override
    public PageResult<ContentCategory> findByPage(Integer page, Integer pageSize) {
        Page<ContentCategory> page1 = this.page(new Page<>(page, pageSize));
        return new PageResult<>(page1.getRecords(),page1.getTotal());
    }

    //分页查询（带条件）
    @Override
    public PageResult<ContentCategory> search(Integer page, Integer pageSize, String name) {
        //封装查询条件
        QueryWrapper<ContentCategory> wrapper = new QueryWrapper<>();
        wrapper.like(StrUtil.isNotBlank(name), "name", name);

        //根据wrapper包装好的条件进行分页查询
        Page<ContentCategory> page1 = this.page(new Page<>(page, pageSize), wrapper);
        return new PageResult<>(page1.getRecords(),page1.getTotal());
    }
}
